
package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmall.user.mapper.AddressMapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements  AddressService {

    @Autowired(required = false)
    private AddressMapper addressMapper;
    /**
     * 根据用户id查询地址列表
     *
     * @param userId
     * @return List<Address>
     */
    @Override
    public List<Address> getById(Long userId) {
        QueryWrapper<Address> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Address> addressList = addressMapper.selectList(wrapper);
        return addressList;
    }

    /**
     * 根据addressId查询地址
     *
     * @param id
     * @return
     */
    @Override
    public Address getByAddressId(Long id) {
        Address address = addressMapper.selectById(id);
        return address ;
    }
}
